import { Color, createWorldTerrain, JulianDate, MaterialProperty } from "cesium";
import dat from "dat.gui";
// import { Jesium } from "../../modules/jesium";
import { Jesium } from "@even_jie/jesium"

/**
 * 图形化界面业务代码
 */
export class GUIBusinessCode {
    gui = new dat.GUI();
    option = {
        time: {
            // 打印当前公历时间
            printCurrentGregorianDate: this.printCurrentGregorianDate.bind(this),
            // 当前小时
            hours: 0
        },
        light: {
            // 开启全局光照
            enableGlobeLighting: false
        },
        weather: {
            enableSnow: false,
            enableRain: false,
            enableFog: false,
            enableOvercast: false,
        },
        measure: {
            enableMeasurePoint: this.enableMeasurePoint.bind(this),
            enableMeasureLineDistance: this.enableMeasurePolylineDistance.bind(this),
            enableMeasurePolygonArea: this.enableMeasurePolygonDistance.bind(this)
        },
        camera: {
            landAlpha: 1,
            enableCollisionDetection: true,
            enableLandTransparent: false
        },
        material: {
            testFlowLine: () => {
                const material1 = this.jesium.materialUtils.getPolylineTrailLinkMaterialProperty(3000, "/images/flowLine.png");
                const material2 = this.jesium.materialUtils.getPolylineTrailLinkMaterialProperty(3000, "/images/DianXianFlowLine.png")
                const entities1 = this.jesium.viewer.entities.add({
                    name: "管线",
                    polyline: {
                        positions: window.Cesium.Cartesian3.fromDegreesArray([
                            75, 38,
                
                            125, 35,
                        ]),
                        width: 4,

                        material: material2, //修改抛物线材质
                    },
                });
                const entities2 = this.jesium.viewer.entities.add({
                    name: "管线",
                    polyline: {
                        positions: window.Cesium.Cartesian3.fromDegreesArray([
                            75, 35,
                
                            125, 35,
                        ]),
                        width: 4,

                        material: material1, //修改抛物线材质
                    },
                });
                console.log(entities1, entities2)
            }
        }
    }
    constructor(private jesium: Jesium) {
        this.time();
        this.light();
        this.weather();
        this.measure();
        this.camera();
        this.material();
    }
    time() {
        const time = this.gui.addFolder("时间相关功能");
        time.add(this.option.time, "printCurrentGregorianDate").name("打印当前公历时间")
        time.add(this.option.time, "hours", 0, 23, 1).name("cesium场景当前小时").onChange(hours => {
            console.log(this.jesium.timeUtils.setHours(hours));
        });
    }
    light() {
        const light = this.gui.addFolder("光源相关功能");
        light.add(this.option.light, "enableGlobeLighting").name("开启全局光照").onChange(value => {
            this.jesium.lightUtils.openGlobeLighting(value);
        })
    }
    measure() {
        const measure = this.gui.addFolder("测量相关功能");
        measure.add(this.option.measure, "enableMeasurePoint").name("启用点测量");
        measure.add(this.option.measure, "enableMeasureLineDistance").name("启用线段距离测量");
        measure.add(this.option.measure, "enableMeasurePolygonArea").name("启用多边形面积测量");
    }
    weather() {
        const weather = this.gui.addFolder("天气相关功能");
        weather.add(this.option.weather, "enableSnow").name("开启雪天").onChange(value => {
            this.jesium.weatherUtils.enableSnowWeather(value);
        })
        weather.add(this.option.weather, "enableRain").name("开启雨天").onChange(value => {
            this.jesium.weatherUtils.enableRainWeather(value);
        })
        weather.add(this.option.weather, "enableFog").name("开启雾天").onChange(value => {
            this.jesium.weatherUtils.enableFogWeather(value);
        })
        weather.add(this.option.weather, "enableOvercast").name("开启阴天").onChange(value => {
            this.jesium.weatherUtils.enableOvercastWeather(value);
        })
    }
    camera() {
        const camera = this.gui.addFolder("相机相关功能");
        camera.add(this.option.camera, "landAlpha", 0, 1).name("设置大地透明度").onChange(value => {
            this.jesium.setLandAlpha(value);
        })
        camera.add(this.option.camera, "enableCollisionDetection").name("开启相机碰撞检测").onChange(value => {
            this.jesium.enableCameraCollisionDetection(value);
        })
        camera.add(this.option.camera, "enableLandTransparent").name("开启大地透明").onChange(value => {
            if(value)
                this.jesium.viewer.terrainProvider = createWorldTerrain()
            this.jesium.enableLandTransparent(value);
        })
    }
    material() {
        const material = this.gui.addFolder("材质相关功能");
        material.add(this.option.material, "testFlowLine").name("测试流线材质")
    }
    /**
     * 打印当前cesium时间的中国公历时间
     */
    printCurrentGregorianDate() {
        console.log(this.jesium.timeUtils.cesiumTimeToGregorianDate())
    }
    /**
     * 启用点测量
     */
    enableMeasurePoint() {
        this.jesium.measureUtils.enableMeasurePoint();
    }
    enableMeasurePolylineDistance() {
        this.jesium.measureUtils.enableMeasurePolylineDistance();
    }
    enableMeasurePolygonDistance() {
        this.jesium.measureUtils.enableMeasurePolygonArea();
    }
}